package com.yn.common.request.zy;


import com.yn.common.constants.Constants;
import com.yn.common.model.zy.SubscribeInfoDO;
import com.yn.common.utils.DateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="就医加号和急诊预约请求对象", description="就医加号和急诊预约")
public class ApptAddInfoRequest {
    // 专家名称
    @ApiModelProperty(value = "专家id")
    @NotBlank(message = "专家信息不能为空")
    private Integer doctorId;

    //业务类型(0:普通预约 1:急诊预约 2:机构预约)
    @ApiModelProperty(value = "业务类型")
    @NotBlank(message = "业务类型不能为空")
    private Integer businessType;

    // 医院名称
    /*@ApiModelProperty(value = "医院名称")
    private String hospitalName;*/

    // 真实姓名（就诊人姓名）
    @ApiModelProperty(value = "真实姓名")
    @NotBlank(message = "真实姓名不能为空")
    private String userOrderName;

    // 手机号码
    @ApiModelProperty(value = "手机号码")
    @NotBlank(message = "手机号码不能为空")
    private String userOrderPhone;

    // 身份证号
    @ApiModelProperty(value = "身份证号")
    @NotBlank(message = "身份证号不能为空")
    private String idCard;

    // 居住地址
    @ApiModelProperty(value = "居住地址")
    private String residenceAddress;

    // 疾病名称
    @ApiModelProperty(value = "疾病名称")
    @NotBlank(message = "疾病名称不能为空")
    private String diseaseName;

    //预约时间
    @ApiModelProperty(value = "预约时间")
    @NotBlank(message = "预约时间不能为空")
    private String apptTime;



    // 备注信息
    @ApiModelProperty(value = "备注信息")
    private String remark;


    public static SubscribeInfoDO transform(ApptAddInfoRequest request) {
    	SubscribeInfoDO infoDO = new SubscribeInfoDO();
        infoDO.setBusinessId(request.getDoctorId());
        infoDO.setBusinessType(request.getBusinessType());
        //infoDO.setHospitalName(request.getHospitalName());
        infoDO.setUserOrderName(request.getUserOrderName());
        infoDO.setUserOrderPhone(request.getUserOrderPhone());
        infoDO.setIdCard(request.getIdCard());
        infoDO.setResidenceAddress(request.getResidenceAddress());
        infoDO.setDiseaseName(request.getDiseaseName());
        Date date = DateUtil.strToDate(request.getApptTime(), Constants.DATE_FORMAT);
        //预约时间不能早于当前时间
        if (date != null && date.getTime() < System.currentTimeMillis()) {
            throw new RuntimeException("预约时间不能早于当前时间");
        }
        infoDO.setApptTime(date);
        if(request.getRemark() != null){
            infoDO.setRemark(request.getRemark());
        }
        return infoDO;
    }
}
